Skip to content

MDEV-39609 - SIGSEGV in process_i_s_table_temporary_tables after failed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint - #5439

Open
pranavktiwari wants to merge 1 commit into
11.4from
11.4-MDEV-39609
Open

MDEV-39609 - SIGSEGV in process_i_s_table_temporary_tables after failed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint#5439
pranavktiwari wants to merge 1 commit into
11.4from
11.4-MDEV-39609

Conversation

@pranavktiwari

@pranavktiwari pranavktiwari commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

fixes MDEV-39609

Problem:

SELECT * FROM information_schema.tables (and SHOW TABLES) crashed with a SIGSEGV in process_i_s_table_temporary_tables() after a failed strict-mode ALTER TABLE on a TEMPORARY table with a zero-default TIMESTAMP column and a CHECK constraint.

Cause:

The failed ALTER marks the temp table needs_reopen. On reopen, Sql_mode_save_for_frm_handling relaxed only parser flags, not the strict/zero-date ones, so evaluating the stored zero TIMESTAMP default was escalated to ER_WRONG_VALUE. open_temporary_table() then failed, leaving the TMP_TABLE_SHARE in temporary_tables with an empty all_tmp_tables. The I_S iteration walked into that empty share and dereferenced a NULL TABLE. Regression in 11.4.

Fix:

Broadened Sql_mode_save_for_frm_handling to also clear MODE_STRICT_TRANS_TABLES, MODE_STRICT_ALL_TABLES, MODE_NO_ZERO_DATE, and MODE_NO_ZERO_IN_DATE while parsing FRM-stored defaults/expressions. Reopening an already-validated temp table now succeeds in any sql_mode, so the empty share is never created and the crash is gone; strictness still applies when new values are written.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts FRM-handling session sql_mode sanitization to additionally clear strict and “no zero date” flags, likely to make .frm parsing/field conversion more permissive during metadata operations.

Changes:

  • Extend the Sql_mode_save_for_frm_handling mask to also clear MODE_STRICT_* and MODE_NO_ZERO_* flags.
  • (Suggested) Align the indentation of the mask continuation lines for readability.
  • (Suggested) Update the nearby explanatory comment to reflect the newly-cleared modes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sql/sql_class.h Outdated
Comment thread sql/sql_class.h
@pranavktiwari pranavktiwari changed the title DRAFT | SIGSEGV in process_i_s_table_temporary_tables after failed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint DRAFT | MDEV-39609 - SIGSEGV in process_i_s_table_temporary_tables after failed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint Jul 23, 2026
@pranavktiwari
pranavktiwari force-pushed the 11.4-MDEV-39609 branch 2 times, most recently from 35eb680 to 2928ac7 Compare July 23, 2026 09:50
@pranavktiwari pranavktiwari changed the title DRAFT | MDEV-39609 - SIGSEGV in process_i_s_table_temporary_tables after failed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint MDEV-39609 - SIGSEGV in process_i_s_table_temporary_tables after failed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint Jul 24, 2026
…ed ALTER TABLE on temporary TIMESTAMP table with CHECK constraint

Problem:
SELECT * FROM information_schema.tables crashed with a SIGSEGV in process_i_s_table_temporary_tables() after a failed strict-mode ALTER TABLE on a TEMPORARY table with a zero-default TIMESTAMP column and a CHECK constraint.

Cause:
The failed ALTER marks the temp table needs_reopen. On reopen, Sql_mode_save_for_frm_handling relaxed only parser flags, not the strict/zero-date ones, so evaluating the stored zero TIMESTAMP default was escalated to ER_WRONG_VALUE. open_temporary_table() then failed, leaving the TMP_TABLE_SHARE in temporary_tables with an empty all_tmp_tables. The I_S iteration walked into that empty share and dereferenced a NULL TABLE. Regression in 11.4.

Fix:
Broadened Sql_mode_save_for_frm_handling to also clear MODE_STRICT_TRANS_TABLES, MODE_STRICT_ALL_TABLES, MODE_NO_ZERO_DATE, and MODE_NO_ZERO_IN_DATE while parsing FRM-stored defaults/expressions. Reopening an already-validated temp table now succeeds in any sql_mode, so the empty share is never created and the crash is gone; strictness still applies when new values are written.
@midenok
midenok self-requested a review July 31, 2026 09:29
@midenok

midenok commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

It is CHECK expression failed on reopen, not DEFAULT expression. I guess, worth to clarify in commit message. Also, can we do the precaution code like this:

--- sql/temporary_tables.cc
+++ sql/temporary_tables.cc
@@ -1098,7 +1098,23 @@ Hunk #1, sql/temporary_tables.cc TABLE *THD::find_temporary_table(const char *key, uint key_length,
         share->all_tmp_tables.remove(table);
         free_temporary_table(table);
         if (share->all_tmp_tables.is_empty())
+        {
           table= open_temporary_table(share, share->table_name.str);
+          if (unlikely(!table))
+          {
+            /*
+              The reopen failed and left the share with an empty
+              all_tmp_tables. Do not keep a TMP_TABLE_SHARE with no TABLE
+              instance in temporary_tables: consumers such as
+              process_i_s_table_temporary_tables() assume every share has at
+              least one open instance and would dereference a NULL TABLE.
+              Remove and free the now-empty share.
+            */
+            temporary_tables->remove(share);
+            free_tmp_table_share(share, false);
+            break;
+          }
+        }
         else
         {
           it.rewind();

or at least DBUG_ASSERT() the table was reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants